package com.itheima.edu.info.manager.service.impl;


import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.service.StudentService;

public class StudentServiceImpl implements StudentService {
    public boolean addStudent(Student student) {
        System.out.println(student.toString());
        //将学生对象传递给surdentDao调用添加方法,返回boolean类型数据
        boolean flag = studentDao.addStudent(student);
        return flag;
    }

    public boolean isExists(String id) {
        Student[] students = studentDao.findAllStudents();
        //假设不存在
        boolean exists = false;
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && id.equals(students[i].getId())) {
                exists = true;
            }
        }
        return exists;
    }

    public boolean delectStudent(String id) {
        boolean result = studentDao.delectStudent(id);
        return result;
    }

    public Student selectStudents(String id) {
        Student stu = studentDao.selectStudent(id);
        return stu;
    }

    public Student updataStudent(Student student) {
        Student newStu = studentDao.updataStudent(student);
        return newStu;
    }

    public Student[] findAllStudent() {
        Student[] students = studentDao.findAllStudents();
        boolean flag = false;
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null)
                flag = true;
        }
        return flag ? students : null;
    }
}